﻿using System;
using Blazing.WebFacade;
using Blazing.BusinessObjects.Products;
using Iesi.Collections.Generic;
using System.Linq;

namespace Blazing.WebShop.UserControls
{
    public partial class ShoppingCart : System.Web.UI.UserControl
    {
        protected override void OnPreRender(EventArgs e)
        {
            Order order = new ProductsController().CurrentOrder;

            var orderList = from i in order.Items
                            group i by i.ID into g
                            select new { Name = g.First().Name, Qty = g.Count() };

            LiteralNoItems.Visible = false;
            if (order.Items.Count > 0)
            {
                RepeaterOrderItems.DataSource = orderList.ToList();
                RepeaterOrderItems.DataBind();
            }
            else
            {
                LiteralNoItems.Visible = true;
                RepeaterOrderItems.DataSource = null;
                RepeaterOrderItems.DataBind();
            }

            base.OnPreRender(e);

        }
    }
}